{#
 # ---------------------------------------------------------------------
 #
 # GLPI - Gestionnaire Libre de Parc Informatique
 #
 # http://glpi-project.org
 #
 # @copyright 2015-2025 Teclib' and contributors.
 # @licence   https://www.gnu.org/licenses/gpl-3.0.html
 #
 # ---------------------------------------------------------------------
 #
 # LICENSE
 #
 # This file is part of GLPI.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 #
 # ---------------------------------------------------------------------
 #}

{% import 'components/form/fields_macros.html.twig' as fields %}

{% if total_number < 1 %}
   <div class="alert alert-info">
      {{ __('No historical') }}
   </div>
{% else %}

   {{ include('components/pager.html.twig', {count: filtered_number}) }}
   <div class="table-responsive">
   <table class="table table-hover">
      <thead>
         <tr>
            <th>{{ __('ID') }}</th>
            <th>{{ _n('Date', 'Dates', 1) }}</th>
            <th>{{ 'User'|itemtype_name }}</th>
            <th>{{ _n('Field', 'Fields', 1) }}</th>
            <th>{{ _x('name', 'Update') }}</th>
            <th>
               <span class="float-end log-toolbar mb-0">
                  <button class="btn btn-sm show_filters {{ filters|length > 0 ? 'btn-secondary active' : 'btn-outline-secondary' }}">
                     <i class="ti ti-filter"></i>
                     <span class="d-none d-xl-block">{{ __('Filter') }}</span>
                  </button>
                  <a href="{{ csv_url }}" class="btn btn-sm text-capitalize btn-outline-secondary">
                     <i class="ti ti-download"></i>
                     <span class="d-none d-xl-block">{{ __('Export') }}</span>
                  </a>
               </span>
            </th>
         </tr>

         {% if filters|length > 0  %}
         <tr class="filter_row">
            <td>
               <input type="hidden" name="filters[active]" value="1" />
               <input type="hidden" name="items_id" value="{{ items_id }}" />
            </td>
            <td>
               {{ fields.dateField(
                  'filters[date]',
                  filters['date'] ?? '',
                  '',
                  {
                     no_label: true,
                     full_width: true,
                     mb: '',
                  },
               ) }}
            </td>
            <td>
               <select name="filters[users_names][]" class="form-select logs-filter-select-multiple" multiple>
                  {% for value, username in user_names %}
                     <option value="{{ value }}" {{ filters['users_names'] is defined and value in filters['users_names'] ? 'selected' : '' }}>
                        {{ username }}
                     </option>
                  {% endfor %}
               </select>
            </td>
            <td>
               <select name="filters[affected_fields][]" class="form-select logs-filter-select-multiple" multiple>
                  {% for value, field in affected_fields %}
                     <option value="{{ value }}" {{ filters['affected_fields'] is defined and value in filters['affected_fields'] ? 'selected' : '' }}>
                        {{ field }}
                     </option>
                  {% endfor %}
               </select>
            </td>
            <td colspan="2">
               <select name="filters[linked_actions][]" class="form-select logs-filter-select-multiple" multiple>
                  {% for value, action in linked_actions %}
                     <option value="{{ value }}" {{ filters['linked_actions'] is defined and value in filters['linked_actions'] ? 'selected' : '' }}>
                        {{ action }}
                     </option>
                  {% endfor %}
               </select>
            </td>
         </tr>
         {% endif %}

      </thead>
      <tbody>
      {% if filtered_number < 1 %}
         <tr><td colspan="6">{{ __('No historical matching your filters') }}</td></tr>
      {% else %}
         {% for entry in logs %}
            {% if entry['display_history'] %}
               <tr>
                  <td>{{ entry['id'] }}</td>
                  <td>{{ entry['date_mod']|formatted_datetime }}</td>
                  <td>{{ entry['user_name'] }}</td>
                  <td>{{ entry['field'] }}</td>
                  <td colspan="2" style="width: 60%">{{ entry['change']|raw }}</td>
               </tr>
            {% endif %}
         {% endfor %}
      {% endif %}
      </tbody>
   </table>
   </div>{# .table-responsive #}

   <div class="ms-auto d-inline-flex align-items-center d-none d-md-block mb-2 my-2">
        {{ __('Entries to show:') }}
        {% include 'components/dropdown/limit.html.twig' %}
   </div>
{% endif %}



<script type="text/javascript">
$(function() {
   $('.logs-filter-select-multiple').select2();
});
</script>
